using System;
using System.Collections.Generic;

namespace Blog.Net.Business.BusinessObjects
{
    /// <summary>
    /// Business Object for BlogEntry.
    /// </summary>
    public partial class BlogEntryBO
    {
        public string LongCreateDate
        {
            get { return CreateDate.ToString("D"); }
        }

        public string ShortBody
        {
            get
            {
                if (Body.Length > 1000)
                {
                    string shortBody = Body.Substring(0, 1000);
                    if (shortBody.LastIndexOf('<') > shortBody.LastIndexOf('>'))
                        shortBody = shortBody.Substring(0, shortBody.LastIndexOf('>') + 1);

                    return shortBody;
                }

                return Body;
            }
        }

        public DateTime? BindCreateDate
        {
            get
            {
                if (CreateDate == null)
                    CreateDate = DateTime.Now;
                return CreateDate;
            }
            set
            {
                if (!value.HasValue)
                    CreateDate = DateTime.Now;
                else
                    CreateDate = value.Value;
            }
        }

        public float Rating
        {
            get
            {
                if (Votes == 0)
                    return 3.0F;

                return (float)Points / (float)Votes;
            }
        }

        public string RatingText
        {
            get
            {
                return string.Format("{0:0.0}", Rating);
            }
        }
    }
}